<?php
# install.php
# Install script. Flaky, needs work once main structure is in place. 
	$install_status = 0;
	$mysql_connect = mysql_connect("localhost", "root", "usmce7"); //connect to mysql
	
	/* MySQL Connection Test */
	
	if ($mysql_connect) {
		echo "Connection with MySQL confirmed";
		$install_status = 1;
	} else {
		echo "Failure to connect with MySQL";
		$install_status = 0;
	}
	
	echo "<br />";
	
	$oscms_db_connect = mysql_select_db("os-cms");
	
	/* Database Connection Test */
	
	if ($oscms_db_connect) {
		echo "Connection with database confirmed";
		$install_status = 1;
	} else {
		echo "Failure to connect with database";
		$install_status = 0;
	}
	
		echo "<br />";
	
############################################################	
	
	$check_user_table = mysql_query("SHOW TABLES FROM os-cms");
	
	$user_table = mysql_query("CREATE TABLE users (id INT  NOT NULL PRIMARY KEY AUTO_INCREMENT, Username CHAR (255), DisplayName CHAR(255), Password CHAR(255), Email CHAR(255), AccessNumber INT);");
	
		echo "<br />";
	
####################################################

echo "Setup Admin User:";

echo " <form name='input' method='post' action='install.php'>
			<p>Username: <input type='text' name='username' id='username' /></p>
			<p>Display Name: <input type='text' name='displayname' id='displayname' /></p>
			<p>Password: <input type='text' name='password' id='password' /></p>
			<p>Email: <input type='text' name='email' id='email' /></p>
		<p><input type='reset' name='reset' value='reset' /> 
<input type='submit' name='submit' value='submit' /></p>
</form>
"; 	

if (isset($_POST['submit'])) {
	$username = $_POST['username'];
	$displayname = $_POST['displayname'];
	$password = $_POST['password'];
	$email = $_POST['email'];
	
		mysql_query("INSERT INTO users VALUES ($username, $displayname, $password, $email, 0)")	;
	}

	$data = mysql_query("SELECT Username FROM users");

	echo $data;
	mysql_close();
	
	if ($install_status == 1) {
		echo "Install completed successfully";
	} else {
		echo "There was a problem with the install.";
		}
		
?> 